"""
@author: jpj
@email: pj.jiang@hzgosun.com
@file: delayConfigurationTest.py
@time: 2019/7/25 10:50

"""
import unittest
from time import sleep

from common.decorators import log4gs, mkdir_classname
from common.settings import TAG
from pages.delayConfigurationPage import DelayConfiguration


@log4gs
@mkdir_classname(TAG)
class DelayConfigurationTest(unittest.TestCase):
    """事件处理延时配置功能测试"""

    @classmethod
    def setUpClass(cls):
        cls.log.info('=' * 30 + '开始事件处理延时配置功能测试' + '=' * 30)
        cls.page = DelayConfiguration('/DataManage/delayConfiguration')

    @classmethod
    def tearDownClass(cls):
        cls.log.info('=' * 30 + "结束事件处理延时配置功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page.driver.quit()

    def setUp(self):
        self.log.info('>>>>>开始执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def tearDown(self):
        sleep(3)
        self.log.info('<<<<<结束执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def test_1_village(self):
        """修改村综治中心24延时"""
        num = 24
        try:
            self.page.village.clear()
            sleep(1)
            self.page.village.send_keys(num)
            sleep(1)
            self.page.button.click()
            sleep(0.2)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("延时{}小时提示框：{}".format(num, self.page.success.text))
            self.log.info("用例{}修改{}小时区综治中心延时执行成功".format(self.id(), num))
        except:
            self.log.error("用例{}修改{}小时区综治中心延时执行失败".format(self.id(), num))

    def test_2_town(self):
        """修改镇综治中心72延时"""
        num = 72
        try:
            self.page.town.clear()
            sleep(1)
            self.page.town.send_keys(num)
            sleep(1)
            self.page.button.click()
            sleep(0.2)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("延时{}小时提示框：{}".format(num, self.page.success.text))
            self.log.info("用例{}修改{}小时区综治中心延时执行成功".format(self.id(), num))
        except:
            self.log.error("用例{}修改{}小时区综治中心延时执行失败".format(self.id(), num))

    def test_3_district(self):
        """修改区综治中心48延时"""
        num = 48
        try:
            self.page.district.clear()
            sleep(1)
            self.page.district.send_keys(num)
            sleep(1)
            self.page.button.click()
            sleep(0.2)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("延时{}小时提示框：{}".format(num, self.page.success.text))
            self.log.info("用例{}修改{}小时区综治中心延时执行成功".format(self.id(), num))
        except:
            self.log.error("用例{}修改{}小时区综治中心延时执行失败".format(self.id(), num))

    def test_4_district(self):
        """修改区综治中心36延时不是24倍数"""
        num = 36
        try:
            self.page.district.clear()
            sleep(1)
            self.page.district.send_keys(num)
            sleep(1)
            self.page.button.click()
            sleep(0.2)
            self.assertEqual(self.page.error.text, "输入范围应小于24或是24的倍数")
            sleep(0.1)
            self.log.info("延时{}小时提示框：{}".format(num, self.page.error.text))
            self.log.info("用例{}执行成功".format(self.id()))
        except:
            self.log.error("用例{}执行失败".format(self.id()))


if __name__ == '__main__':
    unittest.main()